//
//  TabBarController.m
//  KiklinkApp
//
//  Created by LJC on 14-9-2.
//  Copyright (c) 2014年 Kiklink. All rights reserved.
//

#import "TabBarController.h"
#import "BaseNavigationController.h"
#import "HomeViewController.h"
#import "ChosenViewController.h"
#import "LocalViewController.h"
#import "MeViewController.h"

#import "ImagesManager.h"
#import "UIColor+hex.h"

@interface TabBarController ()
@end

@implementation TabBarController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    ImagesManager *imageManager = [ImagesManager sharedImagesManager];
    
    HomeViewController *homeVC = [[HomeViewController alloc] init];
    BaseNavigationController *homeNav = [[BaseNavigationController alloc] initWithRootViewController:homeVC];
    UITabBarItem *homeTabItem = [[UITabBarItem alloc] initWithTitle:@"首页" image:[imageManager tabItemOfIndex:0 selected:NO] selectedImage:[imageManager tabItemOfIndex:0 selected:YES]];
    homeNav.tabBarItem = homeTabItem;
    
    ChosenViewController *chosenVC = [[ChosenViewController alloc] init];
    BaseNavigationController *chosenNav = [[BaseNavigationController alloc] initWithRootViewController:chosenVC];
    UITabBarItem *chosenTabItem = [[UITabBarItem alloc] initWithTitle:@"精选课程" image:[imageManager tabItemOfIndex:1 selected:NO] selectedImage:[imageManager tabItemOfIndex:1 selected:YES]];
    chosenNav.tabBarItem = chosenTabItem;
    
    LocalViewController *localVC = [[LocalViewController alloc] init];
    BaseNavigationController *localNav = [[BaseNavigationController alloc] initWithRootViewController:localVC];
    UITabBarItem *localTabItem = [[UITabBarItem alloc] initWithTitle:@"附近课程" image:[imageManager tabItemOfIndex:2 selected:NO] selectedImage:[imageManager tabItemOfIndex:2 selected:YES]];
    localNav.tabBarItem = localTabItem;
    
    MeViewController *meVC = [[MeViewController alloc] init];
    BaseNavigationController *meNav = [[BaseNavigationController alloc] initWithRootViewController:meVC];
    UITabBarItem *meTabItem = [[UITabBarItem alloc] initWithTitle:@"我的" image:[imageManager tabItemOfIndex:3 selected:NO] selectedImage:[imageManager tabItemOfIndex:3 selected:YES]];
    meNav.tabBarItem = meTabItem;
    
    self.viewControllers = @[homeNav,chosenNav,localNav,meNav];
    self.tabBar.selectedImageTintColor = [UIColor colorWithHexString:AppColor_Main];
    self.tabBar.tintColor = [UIColor colorWithHexString:AppColor_Main];
    self.tabBar.barTintColor = [UIColor colorWithWhite:1.0 alpha:0.94];
    self.delegate = self;
    
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

#pragma mark - TabBarDelegate
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
    [(BaseNavigationController *)viewController popToRootViewControllerAnimated:NO];
}

#pragma mark - TabBarDelegate End

@end
